import React, { Component } from 'react'
import Header from '../../components/header'
import axios from 'axios'
export default class Login extends Component {


    submit= ()=>{
        const {user,pwd} = this.refs;
        
        let obj = {
            user:user.value,
            pwd:pwd.value,
        }
        axios.post('/user/login',obj).then(res=>{
            const {code,msg} = res.data;
            alert(msg)
            if(code === 1){
                this.props.history.push('/home');
                localStorage.user = obj.user;
                return 
            }


        })
    }
    render() {
        return (
            <div>
                <Header />
                <span className="goRe" onClick={()=>this.props.history.push('/register')}>去注册</span>
                <div><input ref="user" type="text" placeholder="请输入账号"/></div>
                <div><input ref="pwd" type="text" placeholder="请输入密码" /></div>
                <div onClick={()=>this.submit()}>登录</div>
            </div>
        )
    }
}
